﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using Microsoft.AspNet.SignalR;
using Microsoft.AspNet.SignalR.Hubs;
using Micua.iChat.Models;

namespace ChatServer.Hubs
{
    [HubName("AccountHub")]
    public class AccountHub : Hub
    {
        public void Login(string username, string password)
        {
            //Thread.Sleep(3000);

            var user = User.Storages.FirstOrDefault(u => u.Username.Equals(username));
            if (user == null || user.Password != password)
            {
                Clients.Caller.LoginFailedCallback("登录失败");
                return;
            }
            user.Status = UserStatus.Online;
            Clients.Caller.LoginSuccessCallback(user);
            Clients.Others.NewFriendComeon(user);
        }
    }
}